<template>
	<view class="page">
		<u--form labelPosition="left" :model="model1" :rules="rules" ref="uForm">

			<u-form-item>
				<template #label class="title">
					<span style="color: red;">*</span>
					<span style="margin-bottom: 120rpx;font-weight: bold;">商户门头/logo:</span>
				</template>

			</u-form-item>
			<u-form-item prop="userInfo.video" borderBottom>
				<u-upload :fileList="fileList3" @afterRead="afterRead" @delete="deletePic" name="3" multiple
					:maxCount="10" :previewFullImage="true"></u-upload>
			</u-form-item>

			<u-form-item prop="userInfo.name" borderBottom ref="item1">
				<template #label class="title">
					<span style="color: red;">*</span>
					<span style="margin-right: 20rpx;font-weight: bold;">商户简称:</span>
				</template>

				<u--input v-model="model1.userInfo.name" border="none" placeholder="请输入商户简称"></u--input>
			</u-form-item>
			<u-form-item prop="userInfo.time" borderBottom ref="item1">
				<template #label class="title">
					<span style="color: red;">*</span>
					<span style="margin-right: 20rpx;font-weight: bold;">营业时间:</span>
				</template>

				<u--input v-model="model1.userInfo.time" border="none" placeholder="请输入营业时间"></u--input>
			</u-form-item>
			<u-form-item prop="userInfo.phone" borderBottom ref="item1">
				<template #label class="title">
					<span style="color: red;">*</span>
					<span style="margin-right: 20rpx;font-weight: bold;">联系电话:</span>
				</template>

				<u--input v-model="model1.userInfo.phone" border="none" placeholder="请输入联系电话"></u--input>
			</u-form-item>
			<u-form-item>
				<template #label class="title">
					<span style="color: red;">*</span>
					<span style="font-weight: bold;">商户介绍:</span>
				</template>
			</u-form-item>
			<uni-forms-item prop="userInfo.firm" borderBottom>
				<u--textarea v-model="value1" placeholder="请输入商户简介内容" height="80" maxlength="150" count="true"
					border="bottom"></u--textarea>
			</uni-forms-item>
		</u--form>
		<view class="bottom">
			<view class="button">
				提交
			</view>
		</view>
	</view>






</template>

<script>
	export default {
		data() {
			return {
				value1: '',
				value2: '',


				paramName: '',
				paramContent: '', // 用于存储输入的参数名

				selectedLabel: '',
				//规格属性
				count: '',
				price: '',
				color: '',
				fileList2: [],
				checkboxValue1: [],


				fileList3: [{
					url: 'https://cdn.uviewui.com/uview/swiper/1.jpg',
				}],
				showFree: false,
				fileList1: [],
				model1: {
					userInfo: {
						name: '',
						phone: '',
						time: '',
						free: '',
						shop: '',
						return: '',
					},
				},

				rules: {
					'userInfo.name': {
						type: 'string',
						required: true,
						message: '请填写商户简称',
						trigger: ['blur', 'change']
					},
					'userInfo.time': {
						type: 'string',
						required: true,
						message: '请填写营业时间',
						trigger: ['blur', 'change']
					},
					'userInfo.phone': {
						type: 'string',
						required: true,
						message: '请填写联系电话',
						trigger: ['blur', 'change']
					},
					'userInfo.firm': {
						type: 'string',
						required: true,
						message: '请填写公司名称',
						trigger: ['blur', 'change']
					},
					'userInfo.free': {
						type: 'string',
						max: 1,
						required: true,
						message: '请选择是否包邮',
						trigger: ['blur', 'change']
					},
				},
				radio: '',
				switchVal: false
			};
		},
		methods: {


			onReady() {
				//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
				this.$refs.uForm.setRules(this.rules)
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},

		}
	}
</script>

<style scoped lang="scss">
	@import 'message.scss';

	.custom-button {
		background-color: #d1a969;
		height: 80rpx;
		text-align: center;
		line-height: 80rpx;
		color: #fff;

		border-radius: 40rpx;
		margin: 20rpx;
	}

	.popup-content .item1 {
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 20rpx 0;
	}

	.popup-content .title {
		margin-top: 20rpx;
		text-align: center;
	}

	.popup-content .button-group {
		display: flex;
		margin-top: 30rpx;
	}

	.popup-content .button-group .item {
		width: 300rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		color: #fff;
		border-radius: 40rpx;
		background-color: $base;
		margin: 0 40rpx;
	}

	.bottom {
		position: fixed;
		bottom: 10rpx;
		border-top: 1rpx solid #ccc;
		padding: 30rpx 20rpx;

		.button {
			width: 660rpx;
			height: 100rpx;
			border-radius: 50rpx;
			background-color: $base;
			line-height: 100rpx;
			text-align: center;
			color: #fff;
		}
	}
</style>